package src.model.gameObject.ability;

import src.event.events.UpdateView;
import src.model.gameObject.GameObject;
import src.model.gameObject.eventBrokers.MoveEventBroker;
import src.model.gameObject.eventInterfaces.MoveGameObjectListener;
import src.model.gameWorld.ActualMap;
import src.model.gameWorld.GameWorldEventHandler;
import src.model.gameWorld.LookupTable;
import src.model.gameWorld.Position;

/**
 * @author Tristan
 *
 */
public class View extends Ability implements MoveGameObjectListener {
	
	private Position viewingFrom;
	private ActualMap am;
	/**
	 * @param go
	 * @param aType
	 */
	public View(GameObject go, ActualMap am, LookupTable lookup) {
		super(go, AbilityType.VIEW, lookup);
		viewingFrom = am.findObject(go);
		MoveEventBroker.register(super.gameObject(), this);
	}

	public int getViewDistance(){
		
		return (int)super.getAttribute(AbilityAttributes.MAXIMUM);
	}
	
	public void notifyGameObjectMoved(Position p){
		UpdateView updater = new UpdateView(viewingFrom, p, (int)getViewDistance());
		GameWorldEventHandler.fireEventNow(updater);
		viewingFrom = p;
	}
		
	public void destroySub(){
		viewingFrom = null;
		am = null;
		MoveEventBroker.unregister(super.gameObject(), this);
	}
}
